// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch
{
	public sealed class FieldCapsRequestParameters : RequestParameters<FieldCapsRequestParameters>
	{
		[JsonIgnore]
		public bool? AllowNoIndices { get => Q<bool?>("allow_no_indices"); set => Q("allow_no_indices", value); }

		[JsonIgnore]
		public IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? ExpandWildcards { get => Q<IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>?>("expand_wildcards"); set => Q("expand_wildcards", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Fields Fields { get => Q<Elastic.Clients.Elasticsearch.Fields>("fields"); set => Q("fields", value); }

		[JsonIgnore]
		public bool? IgnoreUnavailable { get => Q<bool?>("ignore_unavailable"); set => Q("ignore_unavailable", value); }

		[JsonIgnore]
		public bool? IncludeUnmapped { get => Q<bool?>("include_unmapped"); set => Q("include_unmapped", value); }

		[JsonIgnore]
		public string? Filters { get => Q<string?>("filters"); set => Q("filters", value); }

		[JsonIgnore]
		public IEnumerable<string>? Types { get => Q<IEnumerable<string>?>("types"); set => Q("types", value); }
	}

	public sealed partial class FieldCapsRequest : PlainRequestBase<FieldCapsRequestParameters>
	{
		public FieldCapsRequest()
		{
		}

		public FieldCapsRequest(Elastic.Clients.Elasticsearch.Indices? indices) : base(r => r.Optional("index", indices))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceFieldCaps;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public bool? AllowNoIndices { get => Q<bool?>("allow_no_indices"); set => Q("allow_no_indices", value); }

		[JsonIgnore]
		public IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? ExpandWildcards { get => Q<IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>?>("expand_wildcards"); set => Q("expand_wildcards", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Fields Fields { get => Q<Elastic.Clients.Elasticsearch.Fields>("fields"); set => Q("fields", value); }

		[JsonIgnore]
		public bool? IgnoreUnavailable { get => Q<bool?>("ignore_unavailable"); set => Q("ignore_unavailable", value); }

		[JsonIgnore]
		public bool? IncludeUnmapped { get => Q<bool?>("include_unmapped"); set => Q("include_unmapped", value); }

		[JsonIgnore]
		public string? Filters { get => Q<string?>("filters"); set => Q("filters", value); }

		[JsonIgnore]
		public IEnumerable<string>? Types { get => Q<IEnumerable<string>?>("types"); set => Q("types", value); }

		[JsonInclude]
		[JsonPropertyName("index_filter")]
		public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? IndexFilter { get; set; }

		[JsonInclude]
		[JsonPropertyName("runtime_mappings")]
		public Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>? RuntimeMappings { get; set; }
	}

	public sealed partial class FieldCapsRequestDescriptor<TDocument> : RequestDescriptorBase<FieldCapsRequestDescriptor<TDocument>, FieldCapsRequestParameters>
	{
		internal FieldCapsRequestDescriptor(Action<FieldCapsRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public FieldCapsRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceFieldCaps;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public FieldCapsRequestDescriptor<TDocument> AllowNoIndices(bool? allowNoIndices = true) => Qs("allow_no_indices", allowNoIndices);
		public FieldCapsRequestDescriptor<TDocument> ExpandWildcards(IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? expandWildcards) => Qs("expand_wildcards", expandWildcards);
		public FieldCapsRequestDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Fields fields) => Qs("fields", fields);
		public FieldCapsRequestDescriptor<TDocument> Filters(string? filters) => Qs("filters", filters);
		public FieldCapsRequestDescriptor<TDocument> IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
		public FieldCapsRequestDescriptor<TDocument> IncludeUnmapped(bool? includeUnmapped = true) => Qs("include_unmapped", includeUnmapped);
		public FieldCapsRequestDescriptor<TDocument> Types(IEnumerable<string>? types) => Qs("types", types);
		public FieldCapsRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Indices? indices)
		{
			RouteValues.Optional("index", indices);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? IndexFilterValue { get; set; }

		private QueryDsl.QueryContainerDescriptor<TDocument> IndexFilterDescriptor { get; set; }

		private Action<QueryDsl.QueryContainerDescriptor<TDocument>> IndexFilterDescriptorAction { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>? RuntimeMappingsValue { get; set; }

		public FieldCapsRequestDescriptor<TDocument> IndexFilter(Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? indexFilter)
		{
			IndexFilterDescriptor = null;
			IndexFilterDescriptorAction = null;
			IndexFilterValue = indexFilter;
			return Self;
		}

		public FieldCapsRequestDescriptor<TDocument> IndexFilter(QueryDsl.QueryContainerDescriptor<TDocument> descriptor)
		{
			IndexFilterValue = null;
			IndexFilterDescriptorAction = null;
			IndexFilterDescriptor = descriptor;
			return Self;
		}

		public FieldCapsRequestDescriptor<TDocument> IndexFilter(Action<QueryDsl.QueryContainerDescriptor<TDocument>> configure)
		{
			IndexFilterValue = null;
			IndexFilterDescriptor = null;
			IndexFilterDescriptorAction = configure;
			return Self;
		}

		public FieldCapsRequestDescriptor<TDocument> RuntimeMappings(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>> selector)
		{
			RuntimeMappingsValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (IndexFilterDescriptor is not null)
			{
				writer.WritePropertyName("index_filter");
				JsonSerializer.Serialize(writer, IndexFilterDescriptor, options);
			}
			else if (IndexFilterDescriptorAction is not null)
			{
				writer.WritePropertyName("index_filter");
				JsonSerializer.Serialize(writer, new QueryDsl.QueryContainerDescriptor<TDocument>(IndexFilterDescriptorAction), options);
			}
			else if (IndexFilterValue is not null)
			{
				writer.WritePropertyName("index_filter");
				JsonSerializer.Serialize(writer, IndexFilterValue, options);
			}

			if (RuntimeMappingsValue is not null)
			{
				writer.WritePropertyName("runtime_mappings");
				JsonSerializer.Serialize(writer, RuntimeMappingsValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class FieldCapsRequestDescriptor : RequestDescriptorBase<FieldCapsRequestDescriptor, FieldCapsRequestParameters>
	{
		internal FieldCapsRequestDescriptor(Action<FieldCapsRequestDescriptor> configure) => configure.Invoke(this);
		public FieldCapsRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceFieldCaps;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public FieldCapsRequestDescriptor AllowNoIndices(bool? allowNoIndices = true) => Qs("allow_no_indices", allowNoIndices);
		public FieldCapsRequestDescriptor ExpandWildcards(IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? expandWildcards) => Qs("expand_wildcards", expandWildcards);
		public FieldCapsRequestDescriptor Fields(Elastic.Clients.Elasticsearch.Fields fields) => Qs("fields", fields);
		public FieldCapsRequestDescriptor Filters(string? filters) => Qs("filters", filters);
		public FieldCapsRequestDescriptor IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
		public FieldCapsRequestDescriptor IncludeUnmapped(bool? includeUnmapped = true) => Qs("include_unmapped", includeUnmapped);
		public FieldCapsRequestDescriptor Types(IEnumerable<string>? types) => Qs("types", types);
		public FieldCapsRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Indices? indices)
		{
			RouteValues.Optional("index", indices);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? IndexFilterValue { get; set; }

		private QueryDsl.QueryContainerDescriptor IndexFilterDescriptor { get; set; }

		private Action<QueryDsl.QueryContainerDescriptor> IndexFilterDescriptorAction { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>? RuntimeMappingsValue { get; set; }

		public FieldCapsRequestDescriptor IndexFilter(Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? indexFilter)
		{
			IndexFilterDescriptor = null;
			IndexFilterDescriptorAction = null;
			IndexFilterValue = indexFilter;
			return Self;
		}

		public FieldCapsRequestDescriptor IndexFilter(QueryDsl.QueryContainerDescriptor descriptor)
		{
			IndexFilterValue = null;
			IndexFilterDescriptorAction = null;
			IndexFilterDescriptor = descriptor;
			return Self;
		}

		public FieldCapsRequestDescriptor IndexFilter(Action<QueryDsl.QueryContainerDescriptor> configure)
		{
			IndexFilterValue = null;
			IndexFilterDescriptor = null;
			IndexFilterDescriptorAction = configure;
			return Self;
		}

		public FieldCapsRequestDescriptor RuntimeMappings(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>> selector)
		{
			RuntimeMappingsValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (IndexFilterDescriptor is not null)
			{
				writer.WritePropertyName("index_filter");
				JsonSerializer.Serialize(writer, IndexFilterDescriptor, options);
			}
			else if (IndexFilterDescriptorAction is not null)
			{
				writer.WritePropertyName("index_filter");
				JsonSerializer.Serialize(writer, new QueryDsl.QueryContainerDescriptor(IndexFilterDescriptorAction), options);
			}
			else if (IndexFilterValue is not null)
			{
				writer.WritePropertyName("index_filter");
				JsonSerializer.Serialize(writer, IndexFilterValue, options);
			}

			if (RuntimeMappingsValue is not null)
			{
				writer.WritePropertyName("runtime_mappings");
				JsonSerializer.Serialize(writer, RuntimeMappingsValue, options);
			}

			writer.WriteEndObject();
		}
	}
}